﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace MySQLLib
{
    public class Storage_items
    {
        private string[,] storage;
        private MySqlConnection conn;

        // Need to rewrite to fit data class.
/*
        public string[] getItemDataFromId(int id)
        {
            string[] item;

            item = Query.SelectQuery(conn, "storage_items", "*", "id=" + id);

            return item;
        }

        public string[] getItemDataFromSlotAndOwner(int slot, int owner)
        {
            string[] item;

            item = Query.SelectQuery(conn, "storage_items", "*", "(slot=" + slot.ToString() + ") AND (owner=" + owner.ToString() + ")");

            return item;
        }
*/
        public string[,] getItemsFromCharacter(int owner)
        {
            string[,] items = new string[0,this.storage.GetLength(1)];
            int count = 0;

            for (int i = 0; i < this.storage.GetLength(0); i++)
            {
                if (storage[i, 1] == owner.ToString())
                {
                    Other.ResizetwoDimensArray(ref items, this.storage.GetLength(1), items.GetLength(0) + 1);
                    for (int i2 = 0; i2 < this.storage.GetLength(1); i2++)
                    {
                        items[count, i2] = this.storage[i, i2];
                    }
                }
            }

            return items;
        }

        public void deleteItemFromTable(int owner, int slot)
        {
            Query.DeleteQuery(conn,"storage_item","owner=" + owner.ToString() + " AND slot=" + slot.ToString());
        }

        public void refresh()
        {
            string[] columns = new string[1];
            columns[0] = "*";

            this.storage = Query.SelectQuery(conn, "storage_items", columns);
        }

        public void setConnection(MySqlConnection connection)
        {
            this.conn = connection;
        }
    }
}
